package com.bah.tract.client.workstore.tol;

import java.util.Set;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bah.tract.client.WorkLog;
import com.bah.tract.client.workstore.WorkStore;

public class TOLWorkStore extends WorkStore<TOLWork> {

	@Inject
	public TOLWorkStore(final WorkLog workLog) {
		super(workLog, "ChargeNumber");
	}

	@Override
	protected final TOLWork makeWork() {
		return new TOLWork();
	}

	private static final Logger LOG = LoggerFactory.getLogger(TOLWorkStore.class);

	@Override
	protected final void processWork(final Set<TOLWork> totaledWork) {
		// Summarize the hours
		for (final TOLWork w : totaledWork) {
			LOG.debug("Raw time is {}", w.getMinutes());
			// round to 15 minutes
			final double remainder = (w.getMinutes()) % 15;
			int quarters = (int) Math.floor(w.getMinutes() / 15.0);
			if (remainder > 7.5) {
				quarters++;
			}
			w.setMinutes(quarters * 15L);
			LOG.debug("Rounded time is {}", w.getMinutes());
		}
	}
}
